let source = [
  {name: '🐝365资源', url: 'https://chaxun.Truechat365.com/?url='},
  {name: '🐝诺迅资源', url: 'https://www.nxflv.com/?url='},
  {name: '🐝M3U8资源', url: 'https://jx.m3u8.tv/jiexi/?url='},
  {name: '🐝8090资源', url: 'https://www.8090.la/8090/?url='},
  {name: '🐝M2090', url: 'https://.com/?url='},
  {name: '🐝B7', url: 'https://jx.bozrc.com:4433/player/?url='},
  {name: '🐝I豆', url: 'https://jx.aidouer.net/?url='},
  {name: '🐝H8', url: 'https://www.h8jx.com/jiexi.php?url='},
  {name: '🐝⑦鸽', url: 'https://jx.nnxv.cn/tv.php?url='},
  {name: '🐝有妖气', url: 'https://www.1717yun.com/jx/ty.php?url='},
]
let css = "<style>*{margin:0;padding:0;box-sizing:border-box}html,body{width:100%;height:100%}.container{width:100%;height:100%;padding:3% 10%;background-color:#686359;display:flex;flex-direction:column}.videobox{flex:1;border:1px solid #fff;background-image:url(https://cdn.jsdelivr.net/gh/Zrahh/JsDelivr_CDN/assets/img/loading.gif);background-size:80px;background-repeat:no-repeat;background-position:center;background-color:#000}#palybox{width:100%;height:100%}.input-group{display:flex;background-color:#fff;padding:15px}.input-group .url-text{height:40px;background:#f2f3f5;border:1px solid #f2f3f5}.input-group .input{flex:6;text-indent:1em}.input-group .select{flex:1;color:#4078eb}.input-group .btn{flex:1;color:#fff;background:linear-gradient(to right,#56c0f9,#3b95f7);cursor:pointer}.input-group .btn:hover{background:linear-gradient(to right,#ffb199,#fa709a)}.tit-gg{padding:15px;background-color:#fff;color:#999;font-size:14px}</style>"
let js = "<script>let inputDom = document.querySelector('.input');let selectDom = document.querySelector('.select');let btnDom = document.querySelector('.btn');function play(url) {let iframeDom = document.querySelector('iframe');let selectValue = selectDom.value;iframeDom.src = `${selectValue+url}`};btnDom.onclick=function(){let inputValue = inputDom.value.trim();if (inputValue) {play(inputValue);} else {alert('请输入链接，没连接我给你解析个毛线~')}};</script>"
let domStart = '<div class="container"><div class="videobox"><iframe id="palybox" src="" allowtransparency="true" frameborder="0" scrolling="no" allowfullscreen="true"></iframe></div><div class="input-group"><input type="text" class="input url-text" placeholder="请粘贴视频网址>ㅂﾉ ☆" /><select class="select url-text" title="如发现视频无法正常播放请尝试更换视频线路！" id="jk">'
let domEnd = '</select><button type="button" class="btn url-text" title="点击开始解析并开始播放">解析播放</button></div><div class="tit-gg"><span>视频播放异常换线路,接口寻找不易,可直接复制粘贴视频链接</span></div></div>'

function optionDom(url, name) {
  return `<option value="${url}" selected="">${name}</option>`
}

let option = source.reduce((res, cur) => {
  const { name, url } = cur
  return res + optionDom(url, name)
}, '')

let dom = domStart + option + domEnd

function setUrl(value) {
  document.write(`${css+dom+js}`)
  let inputDom = document.querySelector('.input')
  let selectDom = document.querySelector('.select')
  let iframeDom = document.querySelector('iframe')
  inputDom.value = value
  iframeDom.src = `${selectDom.value+value}`
}
chrome.runtime.onMessage.addListener(function (message) {
  if (message.type === 'openPage') {
    document.write(`${css+dom+js}`)
  }
  if (message.type === 'analysis' || message.type === 'currentPage') {
    setUrl(message.value)
  }
})
